package com.jiuyun.servlet;

import com.jiuyun.dao.ExamDao;
import com.jiuyun.dao.impi.ExamDaoImpl;
import com.jiuyun.entity.Exam;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/toexam/*")
public class ExamServlet extends BaseServlet {
    ExamDao dao=new ExamDaoImpl();

    protected void examfind(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("考试查询");
        response.setCharacterEncoding("UTF-8");
        List list=null;
        list=dao.examfind();
        request.setAttribute("list",list);
        request.getRequestDispatcher("/exam.jsp").forward(request,response);

    }

    protected void examidfind(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("考试id查询");
        response.setCharacterEncoding("UTF-8");
        String eid=request.getParameter("eid");
        List examid=dao.examidfind(eid);
        request.setAttribute("examid",examid);
        request.getRequestDispatcher("/exam.jsp").forward(request,response);
    }

    protected void zyfind(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("主页查询");
        response.setCharacterEncoding("UTF-8");
        List list=null;
        list=dao.examfind();
        request.setAttribute("list",list);
        request.getRequestDispatcher("/user-page.jsp").forward(request,response);
    }

    protected void cjksfind(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("试卷查询");
        List list=null;
        list=dao.examfind();
        request.setAttribute("cjks",list);
        request.getRequestDispatcher("/givetest.jsp").forward(request,response);
    }

    protected void cjksidfind(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("试卷id查询");
        String eid=request.getParameter("eid");
        List examid=dao.examidfind(eid);
        request.setAttribute("examid",examid);
        request.getRequestDispatcher("/givetest.jsp").forward(request,response);
    }

    protected void ksdel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("试卷删除");
        String examid=request.getParameter("sc");
        System.out.println(examid);
        dao.examdel(examid);
        request.getRequestDispatcher("/toexam/cjksfind").forward(request,response);
    }


}
